<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
    <style>
        thead tr th {
            text-align: center !important;
        }

        tr td {
            text-align: center !important;
        }

    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-form">
                    <%-- 查询条件设置 --%>
                    <div class="layui-container layui-form-item" >
                        <div class="layui-col-md12">
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">标签名:</div>
                                <div class="layui-col-sm8">
                                    <input type="text" name="tagsName"   placeholder="标签名" autocomplete="off" class="layui-input"/>
                                </div>
                            </div>
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">标签编码:</div>
                                <div class="layui-col-sm8">
                                    <input type="text" name="tagsCode"   placeholder="标签编码" autocomplete="off" class="layui-input"/>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">状态:</label>
                                <div class="layui-input-inline">
                                    <select name="status" class="select">
                                        <option value="">全部</option>
                                        <option value="0">停用</option>
                                        <option value="1">启用</option>
                                    </select>
                                </div>
                            </div>
                            <div  class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">创建时间:</div>
                                <div class="layui-col-sm8">
                                    <input class="layui-input"   placeholder="请选择时间范围" name="yyTime" id="laydate-cn" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-col-md3" style="margin-top: 10px">
                                <div class="layui-col-sm9 layui-col-sm-offset3 sel-button-class" id="sle-div">
<%--                                    <button class="layui-btn" data-type="reload">搜索</button>--%>
                                    <button class="layui-btn layuiadmin-btn-list" lay-submit
                                            lay-filter="LAY-app-contlist-search" id="selectbtn">查询
                                    </button>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<table class="layui-hide" id="productList" lay-filter="productList"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="deactivate">停用</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="enable">启用</a>
</script>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script>
    layui.use(['table','laydate','form'], function(){
        var $ = layui.$, layer = layui.layer, form = layui.form,
            element = layui.element, laydate = layui.laydate, table = layui.table;
        form.render('select');
        laydate.render({
            elem: '#laydate-cn',
            range: '~'
        });

        table.render({
            elem: '#productList'
            ,url:'/sysPushTags/listData'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '推送标签表'
            ,cols: [[
                {field:'tagsName', title:'标签名'},
                {field:'tagsCode', title:'标签编码'},
                {field:'status', title:'状态',
                    templet: function (d) {
                        if (d.status == 0) {
                            return "停用"
                        } else if (d.status == 1) {
                            return "启用"
                        }
                    }
                },
                {field: 'createTime', title: '创建时间', templet:"<div>{{layui.util.toDateString(d.NOTICE_DATE, 'yyyy-MM-dd')}}</div>"},
                {fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]],
            page: true,
            request: {
                pageName: 'current', //页码的参数名称，默认：page
                limitName: 'size' //每页数据量的参数名，默认：limit
            },
        });

        //头工具栏事件
        table.on('toolbar(productList)', function(obj){
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        title: "新增/编辑",
                        area: ['700px', '400px'],
                        content: "/sysPushTags/sysPushTagsSave",
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听弹出框表单提交，massage是修改界面的表单数据'submit(demo11),是修改按钮的绑定
        // function setFormValue(obj,data){
        //     form.on('submit(demo11)', function(massage) {
        //         $.ajax({
        //             url:'/updateCollectorAndConfig',
        //             type:'POST',
        //             data:{
        //                 oldeqptType:data.eqptType,
        //                 oldeqptIdCode:data.eqptIdCode,
        //                 neweqptType:massage.field.neweqptType,
        //                 neweqptIdCode:massage.field.neweqptIdCode,
        //                 eqptName:"修改采集器"},
        //             success:function (msg) {
        //                 var returnCode = msg.returnCode;//取得返回数据（Sting类型的字符串）的信息进行取值判断
        //                 if(returnCode==200){
        //                     layer.closeAll('loading');
        //                     layer.load(2);
        //                     layer.msg("修改成功", {icon: 6});
        //                     setTimeout(function(){
        //                         obj.update({
        //                             eqptType:massage.field.neweqptType,
        //                             eqptIdCode:massage.field.neweqptIdCode,
        //                             eqptName:massage.field.neweqptName
        //                         });//修改成功修改表格数据不进行跳转
        //                         layer.closeAll();//关闭所有的弹出层
        //                     }, 1000);
        //                     加载层-风格
        //                 }else{
        //                     layer.msg("修改失败", {icon: 5});
        //                 }
        //             }
        //         })
        //     })
        //
        // }



        // $('#sle-div .layui-btn').on('click', function(data){
        //     var field = data.field;
        //     //执行重载
        //     table.reload('productList', {
        //         where: field
        //     });
        // });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('productList', {
                where: field
            });
        });

        //监听行工具事件
        table.on('tool(productList)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    title: "新增/编辑",
                    area: ['700px', '400px'],
                    content: "/sysPushTags/sysPushTagsSave?id="+data.id+"&tagsCode="+data.tagsCode+"&tagsName="+data.tagsName+"&status="+data.status,
                });
            } else if(obj.event === 'deactivate'){
                $.ajax({
                    url: "/sysPushTags/deactivate?id="+data.id,
                    dataType: "json",
                    type: "get",
                    success: function (data) {
                        if (data.status) {
                                obj.update({
                                    status: 0
                                });
                        }
                        layer.alert(data.desc);
                    }
                });
            } else if(obj.event === 'enable'){
                $.ajax({
                    url: "/sysPushTags/enable?id="+data.id,
                    dataType: "json",
                    type: "get",
                    success: function (data) {
                        if (data.status) {
                            obj.update({
                                status: 1
                            });
                        }
                        layer.alert(data.desc);
                    }
                });

            }
        });

    });
</script>

</body>
</html>
